package com.sky.mapper;

import com.sky.entity.Orders;
import com.sky.vo.DishOverViewVO;
import com.sky.vo.OrderOverViewVO;
import com.sky.vo.SetmealOverViewVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface WorkSpaceMapper {
    /**
     * 查询今日新增用户
     * @param today
     * @return
     */
    @Select("select count(*) from user where DATE(create_time) = #{today}")
    Integer todayNewUser(LocalDate today);

    /**
     * 查询今日的订单列表
     * @param today
     * @return
     */
    @Select("select * from orders where DATE(order_time) = #{today}")
    List<Orders> todayOrdersList(LocalDate today);

    /**
     * 查询总共套餐总览
     * @return
     */
    @Select("select count(case when status = 0 then 1 end) as discontinued,count(case when status = 1 then 1 end) as sold " +
            "from setmeal")
    SetmealOverViewVO setMealOverView();

    /**
     * 查询总共菜品总览
     * @return
     */
    @Select("select count(case when status = 0 then 1 end) as discontinued," +
            "count(case when status = 1 then 1 end) as sold from dish")
    DishOverViewVO dishesOverView();

    /**
     * 查询总共订单总览
     * @return
     */
    @Select("select count(*) as allOrders," +
            "count(case when status = 6 then 1 end) as cancelledOrders," +
            "count(case when status = 5 then 1 end) as completedOrders," +
            "count(case when status = 3 then 1 end) as deliveredOrders," +
            "count(case when status = 2 then 1 end) as waitingOrders from orders")
    OrderOverViewVO ordersOverView();
}
